from flask import Flask

import os

def create_app():
    app = Flask(__name__)

    # #        if isinstance(obj, str):
    #         obj = import_string(obj)
    #     for key in dir(obj):
    #         if key.isupper():
    #             self[key] = getattr(obj, key)
    #             getattr(obj,key)获取对应key的values
    #加载config.settings的配置到app.config属性
    app.config.from_object("config.settings")

    #从环境变量加载配置
    if 'FLASK_ENV' in os.environ:
        app.config.from_envvar('FLASK_ENV')

    ctx = app.app_context()
    ctx.push()

    #蓝图注册
    import router
    router.init_app(app)

    #绑定orm model
    # import model
    # model.init_app_db()



    return app


#通过自定义Flask类，去实例化核心对象
# class MyAPP(Flask):
#     def __init__(self, *args, **kwargs):
#         Flask.__init__(self, *args, **kwargs)